package org.practice.chart;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: jack
 * Date: 12-5-5
 * Time: 下午10:24
 * To change this template use File | Settings | File Templates.
 */
public class ChartAttributeVO {
    private String chartCaption;
    private String graphProps;
    private List<String> datasetProps;//datasetProperties and setProperties
    private Map<String,String[]> dataMap;
    public ChartAttributeVO(String chartCaption){
        this.chartCaption=chartCaption;
        dataMap=new HashMap<String, String[]>();
        datasetProps=new ArrayList<String>();
    }
    public void addCategories(String[] categoryArr){
        dataMap.put("categories",categoryArr);//(对应横坐标categories)
    }

    /**
     * dataset对应于Categories，为Categories的每个category设值
     * @param values
     */
    public void addDatset(String seriesName,String[] values,String... props){
        dataMap.put(seriesName, values);//(对应横坐标categories)
        String[] colors=new String[]{"00FF00","FFFF00","FF0000","DEDEBE","889E6D","CCCCCC"};
        if (props.length>0){
            datasetProps.add(props[0]);
        }else {
            datasetProps.add(colors[datasetProps.size()]);
        }
        dataMap.put("datasetProperties",datasetProps.toArray(new String[datasetProps.size()]));//(对应横坐标categories)
    }

    /**
     *
     * @param value
     * @param attr(name,color...)
     */
    public void addSet(String value,String... attr){
        StringBuffer sb=new StringBuffer("value='"+value+"' ");
        String[] props=new String[]{"name","color"};
        for(int i = 0;i<attr.length ;i++){
            if(i<props.length){
                String prop = props[i];
                sb.append(prop+"='"+attr[i]+"' ");
            }
        }
        datasetProps.add(sb.toString());
        dataMap.put("setProperties",datasetProps.toArray(new String[datasetProps.size()]));//(对应横坐标categories)

    }

    public void addLink(String[] jsCodeArr){
        dataMap.put("link",jsCodeArr);
    }

    public void setCategoriesProps(String categoriesProps){
        categoriesProps=categoriesProps.replace("=","='").replace(",","' ")+"'";
        dataMap.put("categoriesProps",new String[]{categoriesProps});
    }

    public String getGraphProps() {
        return graphProps;
    }

    public void setGraphProps(String graphProps) {
        this.graphProps = graphProps;
    }

    public List<String> getDatasetProps() {
        return datasetProps;
    }

    public void setDatasetProps(List<String> datasetProps) {
        this.datasetProps = datasetProps;
    }

    public String getChartCaption() {
        return chartCaption;
    }

    public void setChartCaption(String chartCaption) {
        this.chartCaption = chartCaption;
    }

    public Map<String, String[]> getDataMap() {
        return dataMap;
    }

    public void setDataMap(Map<String, String[]> dataMap) {
        this.dataMap = dataMap;
    }
}
